/*
 * @(#)CachePlugInTestCase.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.plugin;

import java.util.HashMap;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;

import com.nhncorp.lucy.common.plugin.PlugInException;
import com.nhncorp.usf.core.cache.CacheKey;
import com.nhncorp.usf.core.cache.CacheManager;
import com.nhncorp.usf.core.cache.CacheStatusException;
import com.nhncorp.usf.core.cache.ResultCacheKey;

/**
 * @author Web Platform Development Team
 */
public class CachePlugInTestCase {

    CacheManager manager = CacheManager.getInstance();
    CachePlugIn plugIn = new CachePlugIn();

    @Before
    public void before() throws PlugInException {
        plugIn.setDefaultExpire("100");
        plugIn.setSize("500");
        plugIn.setClassName("com.nhncorp.usf.core.cache.ResultCache");
        plugIn.init();
    }

    @Test
    public void initTest() throws CacheStatusException {
        CacheManager manager = CacheManager.getInstance();
        CacheKey key = new ResultCacheKey("bo", "method", new HashMap<String, Object>());
        try {
            manager.addCache(key, "value");
        } catch(Exception e) {
            assertTrue(false);
        }

        assertEquals(plugIn.getClassName(), "com.nhncorp.usf.core.cache.ResultCache");
        assertEquals(plugIn.getDefaultExpire(), String.valueOf(100));
        assertEquals(plugIn.getSize(), String.valueOf(500));
        assertTrue(true);
    }

    @Test
    public void initErrorTest() throws CacheStatusException {
        plugIn.setDefaultExpire(null);
        plugIn.setSize(null);
        plugIn.setClassName(null);
        try {
            plugIn.init();
        } catch(PlugInException e) {
            assertTrue(true);
        }
    }
}
